package com.zlt.healthpass.service.impl;

import com.zlt.healthpass.bean.*;
import com.zlt.healthpass.dao.IUserInfoDao;
import com.zlt.healthpass.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: HealthPass
 * @description: 接口的实现
 * @author: Mr.abel(ShiJiaYi)
 * @create: 2022-07-13 14:17
 **/
//implements 实现接口
//@Service 代表它是业务逻辑层
@Service
public class UserInfoService implements IUserInfoService {
    //业务逻辑层和dao层的通道
    @Autowired
    private IUserInfoDao iuid;

    /**
     * 用于编写查询用户信息的逻辑
     */
    @Override
    public UserInfo selectUserInfoByNickname(String nickname) {
        UserInfo userInfo = iuid.selectUserInfoByNickname(nickname);
        return userInfo;
    }

    @Override
    public int selectHealthStatusByNickname(String nickname) {
        int i = iuid.selectHealthStatusByNickname(nickname);
        return i;
    }

    @Override
    public int insertLocaltionCode(Localtion localtion) {
        int i = iuid.insertLocaltionCode(localtion);
        return i;
    }

    @Override
    public NucleicAcidTest selectTestByUserId(int userId) {
        NucleicAcidTest nucleicAcidTest = iuid.selectTestByUserId(userId);
        return nucleicAcidTest;
    }

    @Override
    public int uninfected(NucleicAcidTestSub nats) {
        int uninfected = iuid.uninfected(nats);
        return uninfected;
    }


    @Override
    public int infected(NucleicAcidTestSub nats) {
        //查询出14天内所有去过的场所
        List<InfectedLocation> infectedLocation = iuid.getInfectedLocation(nats);

        for (InfectedLocation location : infectedLocation) {
            System.out.println("location.getCreateTime() = " + location.getCreateTime());
            System.out.println("location.getLocationName() = " + location.getLocationName());
            //执行黄码
            iuid.updateUserHealthStatus(location);
            //执行红码
            iuid.updateUserHealthStatusRed(location);
        }
        return 1;
    }

    @Override
    public int insertLocationMsg(LocationMsg lm) {
        return iuid.insertUserLocationMsg(lm);
    }
}
